package client;

public class Monitor {
	private int receivedCommand;
	private int sendCommand;
	private String receivedData;
	private String sendData;

	/**
	 * Starts the monitor.
	 * Its' purpose is to handle all the shared data, such as the image queue,
	 * and the communication-settings.
	 */
	public Monitor(){
		receivedCommand = 0;
		sendCommand = 0;
		receivedData = "";
		sendData = "";
	}

	public synchronized String getSenddata() {
		while (sendData == ""){
			try{
				wait();
			} catch (InterruptedException e) { }
		}
		String tempString = String.valueOf(sendCommand) + sendData;
		sendData = "";
		sendCommand = 0;
//		notifyAll();
		return tempString;
	}

	public synchronized void setDisplayMessage(int recCommand, String dataString) {
		receivedCommand = recCommand;
		receivedData = dataString;
		notifyAll();
	}

	public synchronized void setSendData(int sendCmd, String dataString) {
		sendCommand = sendCmd;
		sendData = dataString;
		notifyAll();
	}

	public synchronized String getDisplayMessage() {
		while (receivedCommand == 0){
			try{
				wait();
			} catch (InterruptedException e) { }
		}
		String tmpOut = receivedData;
		receivedCommand = 0;
		receivedData = "";
		return tmpOut;
	}
}